package com.bs.areport.action.master;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bs.areport.service.master.UserRightDao;
import com.bs.areport.service.util.DataUtil;
import com.bs.areport.service.util.EntityType;
import com.bs.restframework.context.SystemContext;
import com.bs.restframework.context.util.SystemContextUtil;
import com.bs.restframework.db.Database;
import com.bs.restframework.session.UserSession;
import com.bs.restframework.web.result.ResultModle;
import com.bs.restframework.web.result.ResultType;

public class UserRightAction {
	private UserRightDao dao;
	public  UserRightDao getDao() {
		return dao;
	}

	public void setDao(UserRightDao dao) {
		this.dao = dao;
	}
	
	/**
	 * 
	 * <p>函数名称：getLogRights</p>
	 * <p>功能说明：获取登录用户权限</p>
	 * <p>参数说明：</p>
	 * <p>创建时间：2012-03-08</p>
	 * <p>作者：李新宇</p>
	 */
	public ResultModle getLogRights() throws Exception
	{
		Map<String, Object> params = SystemContext.getInParams();
		Map<String, Object> resultBean =new HashMap<String, Object>();
		UserSession userSession = SystemContextUtil.getSessionMange().getUserSession((String)params.get("Token"));
		
		if(userSession.isLogin()){
			resultBean.put("userName", userSession.getUserName());
			resultBean.put("deptID", userSession.getAttribute("deptID"));
			resultBean.put("right", userSession.getAttribute("right"));
			resultBean.put("lastTime", userSession.getAttribute("lastTime"));
		}
		return new ResultModle(ResultType.OUTPUT_JSON_STREAM, "user",  resultBean);
	}
	
	/**
	 * 
	 * <p>函数名称：userTree</p>
	 * <p>功能说明：获取用户树/p>
	 * <p>参数说明：</p>
	 * <p>创建时间：2012-03-13</p>
	 * <p>作者：李新宇</p>
	 */
	public ResultModle userTree() throws Exception
	{	
		Map<String, Object> params = SystemContext.getInParams();

		List<Map> listMap = dao.userTree(params) ;
		
		return new ResultModle(ResultType.OUTPUT_JSON_STREAM, "user", listMap);
	}
	
	/**
	 * 
	 * <p>函数名称：rightTree</p>
	 * <p>功能说明：获取/p>
	 * <p>参数说明：</p>
	 * <p>创建时间：2012-03-08</p>
	 * <p>作者：李新宇</p>
	 */
	public ResultModle rightTree() throws Exception
	{	
		Map<String, Object> params = SystemContext.getInParams();
		
		List<Map> list=dao.rightTree(params);
		
		return new ResultModle(ResultType.OUTPUT_JSON_STREAM, "user", list);
	}
	
	/**
	 * 
	 * <p>函数名称：getUserRight</p>
	 * <p>功能说明：获取用户权限/p>
	 * <p>参数说明：</p>
	 * <p>创建时间：2012-03-13</p>
	 * <p>作者：李新宇</p>
	 */	
	public ResultModle getUserRight()  throws Exception
	{
		Map<String, Object> params = SystemContext.getInParams();
		List<Map> list=dao.getUserRight(params);
		
		return new ResultModle(ResultType.OUTPUT_JSON_STREAM, "user", list);
	}
	
	
	/**
	 * 
	 * <p>函数名称：updateUserRight</p>
	 * <p>功能说明：更新用户权限/p>
	 * <p>参数说明：</p>
	 * <p>创建时间：2012-03-13</p>
	 * <p>作者：李新宇</p>
	 */	
    public ResultModle updateUserRight()  throws Exception
    {
    	Map<String, Object> params = SystemContext.getInParams();
    	String userId=(String)params.get("userId");
    	String rightIds=(String)params.get("rightIds");
    	dao.updateUserRight(userId, rightIds);
    	return new ResultModle(ResultType.OUTPUT_JSON_STREAM, "user", "");
    }
}
